home *** CD-ROM | disk | FTP | other *** search
- Path: news.unt.edu!news
- From: Steve Fogoros <sfogoros@hsc.unt.edu>
- Newsgroups: comp.lang.c
- Subject: Re: 6 byte real to double; How?
- Date: Fri, 23 Feb 1996 09:40:02 -0800
- Organization: University of North Texas Health Science Center
- Message-ID: <312DFBF2.74BB@hsc.unt.edu>
- References: <3128306A.21F@hsc.unt.edu> <4gg88a$3oi@aphex.direct.ca>
- NNTP-Posting-Host: sfogoros.hsc.unt.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (Win16; I)
-
- Ed Toivanen wrote:
- >
- > In article <3128306A.21F@hsc.unt.edu>, sfogoros@hsc.unt.edu says...
- > >
- > >I have a lot of data files that were created by a pascal program. The
- > >data is stored as 'file of real' meaning that each floating point value
- > >is stored in six bytes. I need to access this data from a c program
- > >(borland). I would like any assistance you could provide. I guess what
- > >I need is a canned function that would take a 6 byte string (actually the
- > >real), and return a double.
- >
- > You need to know exactly how reals are interpreted by your pascal program. The
- > exact handling of a float is different(X bytes on the left side of the decimal,
- > Y bytes for precision) even across different C compilers, so I don't think
- > pascal would be much different in that respect. Once you know that, the rest is
- > a few C line away.
- >
- > EdThank you for taking some time to consider my question. I should explain
- though that I am not referring to the ascii representation of floating
- point values, but the binary storage format. A six byte real (48 bits) is
- divided into three fields: one sign bit (s), 39 bits for the significand
- (f), and 8 bits for the exponent (e). According to Borland specification
- the value is calculated as:
- if 0 < e <= 255 then value = (-1)**s * 2**(e-129) * (1.f),
- if e == 0 then value = 0.
- A double has one sign bit, 52 bits for the significand (which includes a
- sign bit), and 11 bits for the exponent.
-
- The part I'm not sure about is biasing the exponents. The real is biased
- by 129 and the double is biased by 1023. (I think/hope I've got that
- right). So, if the real exponent is not zero, I add 894 to it and store
- the result in the double exponent (11 bits). I would go with this except
- some numbers convert correctly and some don't. (My testing protocol could
- be in error as well.)
-
- I thought you would be interested in a more detailed description of the
- problem. Also, others may have misunderstood my original question and I
- hope this clarifies things.
- --
- Steve Fogoros, Academic Information Coordinator
- University of North Texas Health Science Center
- 3500 Camp Bowie Boulevard, Fort Worth, Texas 76107-2699
- (817)-735-2162 sfogoros@hsc.unt.edu
-